1   package org.apache.lucene.index;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import java.io.IOException;
21  import java.util.Map;
22  
23  
24  /**
25   * A {@link MergePolicy} which never returns merges to execute. Use it if you
26   * want to prevent segment merges.
27   */
28  public final class NoMergePolicy extends MergePolicy {
29  
30    /** Singleton instance. */
31    public static final MergePolicy INSTANCE = new NoMergePolicy();
32  
33    private NoMergePolicy() {
34      super();
35    }
36  
37    @Override
38    public MergeSpecification findMerges(MergeTrigger mergeTrigger, SegmentInfos segmentInfos, IndexWriter writer) { return null; }
39  
40    @Override
41    public MergeSpecification findForcedMerges(SegmentInfos segmentInfos,
42               int maxSegmentCount, Map<SegmentCommitInfo,Boolean> segmentsToMerge, IndexWriter writer) { return null; }
43  
44    @Override
45    public MergeSpecification findForcedDeletesMerges(SegmentInfos segmentInfos, IndexWriter writer) { return null; }
46  
47    @Override
48    public boolean useCompoundFile(SegmentInfos segments, SegmentCommitInfo newSegment, IndexWriter writer) {
49      return newSegment.info.getUseCompoundFile();
50    }
51  
52    @Override
53    protected long size(SegmentCommitInfo info, IndexWriter writer) throws IOException {
54      return Long.MAX_VALUE;
55    }
56  
57    @Override
58    public String toString() {
59      return "NoMergePolicy";
60    }
61  }